home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / fs / putc.c < prev    next >
C/C++ Source or Header  |  1990-07-23  |  1KB  |  53 lines

  1. /* FS must occasionally print some message.  It uses the standard library
  2.  * routine printf(), which calls putc() and flush. Library
  3.  * versions of these routines do printing by sending messages to FS.  Here
  4.  * obviously can't do that, so FS calls the TTY task directly.
  5.  */
  6.  
  7. #include "fs.h"
  8. #include <minix/com.h>
  9.  
  10. #define STDOUTPUT          1    /* file descriptor for standard output */
  11. #define BUFSIZE          100    /* print buffer size */
  12.  
  13. PRIVATE int bufcount;        /* # characters in the buffer */
  14. PRIVATE char printbuf [BUFSIZE];    /* output is buffered here */
  15. PRIVATE message putchmsg;    /* used for message to TTY task */
  16.  
  17. FORWARD void flush();
  18.  
  19. /*===========================================================================*
  20.  *                putc                         *
  21.  *===========================================================================*/
  22. PUBLIC void putc(c)
  23. char c;
  24. {
  25.  
  26.   if (c == 0) {
  27.     flush();
  28.     return;
  29.   }
  30.   printbuf[bufcount++] = c;
  31.   if (bufcount == BUFSIZE) flush();
  32.   if (c == '\n') flush();
  33. }
  34.  
  35.  
  36. /*===========================================================================*
  37.  *                flush                         *
  38.  *===========================================================================*/
  39. PRIVATE void flush()
  40. {
  41. /* Flush the print buffer. */
  42.  
  43.  
  44.   if (bufcount == 0) return;
  45.   putchmsg.m_type = TTY_WRITE;
  46.   putchmsg.PROC_NR  = 1;
  47.   putchmsg.TTY_LINE = 0;
  48.   putchmsg.ADDRESS  = printbuf;
  49.   putchmsg.COUNT = bufcount;
  50.   rw_dev(TTY, &putchmsg);
  51.   bufcount = 0;
  52. }
  53.